﻿using System;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Linq;


namespace BanditGame
{
    /// <summary>
    /// Information about a game
    /// </summary>
    class Game
    {
        //private int _score = 0;
        ///// <summary>
        ///// Score of the current player
        ///// </summary>
        //public int Score
        //{
        //    get { return _score; }
        //    set
        //    {
        //        _score = value;
        //        //Globals.TextScore.Text = _score.ToString();
        //    }
        //}

        //private int _life = 0;
        ///// <summary>
        ///// Life of the current player
        ///// </summary>
        //public int Life
        //{
        //    get { return _life; }
        //    set
        //    {
        //        _life = value;
        //        //Globals.TextLife.Text = _life.ToString();
        //    }
        //}

        //private int _currentLevelNumber = 1;
        ///// <summary>
        ///// Current level number
        ///// </summary>
        //public int CurrentLevelNumber
        //{
        //    get { return _currentLevelNumber; }
        //    set { _currentLevelNumber = value; }
        //}


        //private Bandit _myBandit;
        //public Bandit MyBandit
        //{
        //    get { return _myBandit; }
        //    set { _myBandit = value; }
        //}

        //private Level _currentLevel = new Level();
        //public Level CurrentLevel
        //{
        //    get { return _currentLevel; }
        //    set { _currentLevel = value; }
        //}

        //public Game(Level level, Bandit myBandit)
        //{
        //    CurrentLevelNumber = 1;
        //    CurrentLevel = level;
        //    Score = 0;
        //    MyBandit = myBandit;
        //}

        ////TODO - osetrit neexistujici level
        ///// <summary>
        ///// Loading current level
        ///// </summary>
        ///// <returns>CurrentLevel</returns>
        //public Level LoadCurrentLevel()
        //{
        //    Level returnLevel = new Level();
            
        //    try
        //    {
        //        XDocument xdoc = XDocument.Load(string.Format("Levels/{0}.xml", CurrentLevelNumber.ToString("0000")));

        //        if (xdoc != null)
        //        {
        //            var xmlLevel =
        //                (from l in xdoc.Descendants("Level")
        //                 //where (int)l.Attribute("LevelNumber") == actualLevelNumber
        //                 select new Level()
        //                            {
        //                                LevelNumber = Convert.ToInt32(l.Attribute("levelNumber").Value),
        //                                StartingX = Convert.ToInt32(l.Attribute("startingX").Value),
        //                                StartingY = Convert.ToInt32(l.Attribute("startingY").Value),
        //                                SizeX = Convert.ToInt32(l.Attribute("sizeX").Value),
        //                                SizeY = Convert.ToInt32(l.Attribute("sizeY").Value),
        //                                cellList = (from c in l.Descendants("Cell")
        //                                            select new Cell
        //                                                       {
        //                                                           CellType =
        //                                                               Convert.ToChar(c.Attribute("CellType").Value),
        //                                                           PositionX =
        //                                                               Convert.ToInt32(c.Attribute("PositionX").Value),
        //                                                           PositionY =
        //                                                               Convert.ToInt32(c.Attribute("PositionY").Value)
        //                                                       }).ToList()
        //                            }
        //                ).FirstOrDefault();
        //            returnLevel=xmlLevel;
        //        }
        //    }
        //    catch (Exception e)
        //    {
        //        //LEVEL NEEXISTUJE NEBO JE SPATNE DEFINOVAN
        //        //ERROR MSG
        //    }
        //    return returnLevel;
        //}





























        ///// <summary>
        ///// The state of the current game
        ///// </summary>
        ////public GameState State;

        //public Game(Level level, UIElement paddle, params Panel[] paddleStates)
        //{
        //    // initialize game
        //    Level = level;
        //    Score = 0;
        //    //State = GameState.NotStarted;
        //    //PaddleCount = Defaults.InitialPaddleCount;

        //    //// create default ball
        //    //Ball ball = new Ball(Globals.ToScreen(Defaults.BallPos), Defaults.BallDirection,
        //    //    Defaults.BallSpeed, BallState.Normal);
        //    //Balls.Add(ball);

        //    //Paddle = new Paddle(paddle, paddleStates);
        //}

        ///// <summary>
        ///// Resets all balls, the paddle, removes existing bricks (if any)
        ///// adds new bricks and starts new level
        ///// </summary>
        ///// <param name="newLevel"></param>
        //public void StartNewLevel(Level newLevel)
        //{
        //    Level = newLevel;
        //    RestartLevel();
        //   // Globals.PanelTexts.Visibility = Visibility.Visible;
        //}

        ///// <summary>
        ///// Sets the game in a game over state
        ///// </summary>
        //public void GameOver()
        //{
        //    RestartLevel();
        //    //this.Balls[0].PosScreen = new Point(-100, -100);
        //    //this.State = GameState.GameOver;
        //    //Globals.PanelRoot.Cursor = Cursors.Arrow;
        //    //Globals.HighscoreControl.ShowHighscore(Score);
        //}

        ////public bool FirstLevelAfterGameOver = true;
        //public void RestartAfterGameOver()
        //{
        //    //Globals.PanelTexts.Visibility = Visibility.Visible;
        //    //this.Life = Defaults.InitialPaddleCount;
        //    //this.State = GameState.NotStarted;
        //    //_currentLevel = 0;
        //    //Score = 0;
        //    //StartNewLevel(Globals.GetLevel(_currentLevel));
        //    //FirstLevelAfterGameOver = true;
        //}

        ///// <summary>
        ///// Restarts the current level
        ///// </summary>
        //public void RestartLevel()
        //{
        //    //FirstLevelAfterGameOver = false;
        //    //this.State = GameState.NotStarted;

        //    //// reset paddle to middle of screen
        //    //Paddle.ResetToDefault();

        //    //// reset balls states
        //    //for (int i = Balls.Count - 1; i >= 1; i--)
        //    //{
        //    //    Ball ball = Balls[i];
        //    //    Balls.RemoveAt(i);
        //    //    ball.StopMoving();
        //    //    ball.RemoveFromScreen();
        //    //}

        //    //Balls[0].StopMoving();
        //    //Balls[0].PosScreen = Globals.ToScreen(Defaults.BallPos);
        //    //Balls[0].Direction = Defaults.BallDirection;
        //    //Balls[0].State = BallState.Normal;
        //    //Balls[0].Radius = Defaults.BallRadius;
        //    //Balls[0].Speed = Defaults.BallSpeed;

        //    //// remove all existing bonuses
        //    //for (int i = Bonuses.Count - 1; i >= 0; i--)
        //    //{
        //    //    Bonuses[i].StopMoving();
        //    //    Bonuses[i].RemoveFromScreen();
        //    //    Bonuses.RemoveAt(i);
        //    //}

        //    //Globals.TextLevelName.Text = Level.Name;
        //    //CreateAndUpdateBrickImages();
        //}

        //public void BeginPlaying()
        //{
        ////    this.State = GameState.Playing;
        ////    Globals.PanelTexts.Visibility = Visibility.Collapsed;
        ////    Globals.PanelRoot.Cursor = Cursors.None;
        ////    foreach (Ball ball in Balls)
        ////    {
        ////        ball.StartMoving();
        ////    }
        //}



    }
}
